<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>echarts</title>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/echarts/5.5.1-rc.1/echarts.min.js"></script>
</head>

<body>
  <div id="main"></div>
  <style>
    #main {
      width: 100%;
      height: 400px;
    }
  </style>

  <script>
    const chart = echarts.init(document.getElementById('main'));
    let option = {
      title: {
        text: 'Waterfall Chart',
        subtext: 'Living Expenses in Shenzhen'
      },
      tooltip: {
        trigger: 'axis',
        axisPointer: {
          type: 'shadow'
        },
        formatter: function (params) {
          var tar = params[1];
          return tar.name + '<br/>' + tar.seriesName + ' : ' + tar.value;
        }
      },
      grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
      },
      xAxis: {
        type: 'category',
        splitLine: { show: false },
        data: ['Total', 'Rent', 'Utilities', 'Transportation', 'Meals', 'Other']
      },
      yAxis: {
        type: 'value',
        min: 2019,

      },
      series: [
        {
          name: 'Placeholder',
          type: 'bar',
          stack: 'Total',
          itemStyle: {
            borderColor: 'transparent',
            color: 'transparent'
          },
          emphasis: {
            itemStyle: {
              borderColor: 'transparent',
              color: 'transparent'
            }
          },
          data: [2019, 2020, 2023]
        },
        ...['red', 'blue'].map((e) => {
          return {
            name: 'Life Cost',
            type: 'bar',
            stack: 'Total',
            label: {
              show: true,
              position: 'inside'
            },
            color: e,
            data: [1, 1, 1]
          }
        })
      ]
    };
    chart.setOption(option)
  </script>
</body>

</html>